import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;

public class Triangle implements IShape {
    Point ptA, ptB, ptC;

    public Triangle(Point ptA, Point ptB, Point ptC) {
        this.ptA = ptA;
        this.ptB = ptB;
        this.ptC = ptC;
    }

    @Override
    public double perimeter() {
        return distance(ptA, ptB) + distance(ptB, ptC) + distance(ptC, ptA);
    }

    @Override
    public double area() {
        double s = perimeter() / 2;
        return Math.sqrt(s * (s - distance(ptA, ptB)) * (s - distance(ptB, ptC)) * (s - distance(ptC, ptA)));
    }

    private double distance(Point p1, Point p2) {
        return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
    }

    @Override
    public void draw(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        Polygon triangle = new Polygon(new int[]{ptA.x, ptB.x, ptC.x}, new int[]{ptA.y, ptB.y, ptC.y}, 3);
        g2d.drawPolygon(triangle);
    }
}